import React from 'react';
import { connect } from 'dva';

import Menu from './../components/Menu.js';

class BasicLayout extends React.Component {
    render() {
        const { user, children } = this.props;

        console.log(this.props);

        return (
            <div>
                <h2>BasicLayout</h2>
                <h3>当前用户信息：</h3>
                <p>
                    用户名：{user.name}
                    <br />
                    姓名：{user.realName}
                    <br />
                    注册日期：{user.registerDate}
                </p>
                <p>
                    <a
                        onClick={e => {
                            this.handleLogout(e);
                        }}
                    >
                        退出
                    </a>
                </p>

                <Menu />

                {children}
            </div>
        );
    }
    handleLogout(e) {
        this.props.dispatch({
            type: 'user/logout',
            payload: '',
        });
    }
}

export default connect(function(state) {
    return {
        user: state.user.user,
    };
})(BasicLayout);
